<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('活动列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>标题：</p>
                            <input type="text" name="title"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="activity:activity:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editFull()"
               shiro:hasPermission="activity:activity:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="activity:activity:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="activity:activity:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('activity:activity:edit')}]];
    var removeFlag = [[${@permission.hasPermi('activity:activity:remove')}]];
    var checkFlag = [[${@permission.hasPermi('article:article:check')}]];
    var publishFlag = [[${@permission.hasPermi('article:article:publish')}]];
    var statusDatas = [[${@dict.getType('sys_activity_status')}]];
    var isCheckDatas = [[${@dict.getType('sys_check_status')}]];
    var prefix = ctx + "activity/activity";

    $(function () {
        var options = {
            url: prefix + "/list/" + [[${menuId}]],
            createUrl: prefix + "/add/" + [[${menuId}]],
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "活动",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'null',
                    visible: false
                },
                /*{
                    field: 'dept.deptName',
                    title: '所属区域'
                },*/
                {
                    field: 'title',
                    title: '活动名称'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                       if (row.status == 0){
                           return row.status ="未开始"
                       } else if (row.status == 1){
                            return row.status ="进行中"
                        } else if (row.status == 2){
                            return row.status ="已结束"
                        }
                    }
                },
                {
                    field: 'startTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                /*{
                    field: 'tpe',
                    title: '0普通类型'
                },*/
                {
                    field: 'clickCount',
                    title: '点击数'
                },
                {
                    field: 'likes',
                    title: '点赞数'
                },
                {
                    field: 'isCheck',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(isCheckDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if (row.isCheck == 0) {
                            actions.push('<a class="btn btn-success btn-xs ' + checkFlag + '" href="javascript:void(0)" onclick="check(\'' + row.id + '\')"><i class="fa fa-edit"></i>审核</a>');
                        }
                        if (row.isCheck == 1) {
                            actions.push('<a class="btn btn-danger btn-xs ' + checkFlag + '" href="javascript:void(0)" onclick="cancelCheck(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消审核</a>');
                            if (row.isPublish == 0) {
                                actions.push('<a class="btn btn-info btn-xs ' + publishFlag + '" href="javascript:void(0)" onclick="publish(\'' + row.id + '\')"><i class="fa fa-plus"></i>发布</a> ');
                            } else if (row.isPublish == 1) {
                                actions.push('<a class="btn btn-danger btn-xs ' + publishFlag + '" href="javascript:void(0)" onclick="publish(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消发布</a> ');
                            }
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function check(id) {
        var url = prefix + "/check/" + id;
        $.modal.open("列表", url, "720", "600")
    }

    function cancelCheck(id) {
        table.set();
        $.modal.confirm("确定取消审核吗？", function () {
            var url = prefix + "/cancelCheck";
            if (table.options.type == table_type.bootstrapTreeTable) {
                $.operate.get(url);
            } else {
                var data = {"id": id};
                $.operate.submit(url, "post", "json", data);
            }
        });

    }
    function publish(id) {
        var url = prefix + "/publish";
        var data = {"id": id};
        $.operate.submit(url, "post", "json", data);
    }
</script>
</body>
</html>